/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Andriy
 */
@Entity
@Table(name = "PRODUCT_LIST")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ProductList.findAll", query = "SELECT p FROM ProductList p"),
    @NamedQuery(name = "ProductList.findByCount", query = "SELECT p FROM ProductList p WHERE p.count = :count"),
    @NamedQuery(name = "ProductList.findByIdProduct", query = "SELECT p FROM ProductList p WHERE p.productListPK.idProduct = :idProduct"),
    @NamedQuery(name = "ProductList.findByIdOrder", query = "SELECT p FROM ProductList p WHERE p.productListPK.idOrder = :idOrder")})
public class ProductList implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductListPK productListPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "COUNT")
    private BigInteger count;
    @JoinColumn(name = "ID_PRODUCT", referencedColumnName = "ID_PRODUCT", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Product product;
    @JoinColumn(name = "ID_ORDER", referencedColumnName = "ID_ORDER", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Orders orders;

    public ProductList() {
    }

    public ProductList(ProductListPK productListPK) {
        this.productListPK = productListPK;
    }

    public ProductList(ProductListPK productListPK, BigInteger count) {
        this.productListPK = productListPK;
        this.count = count;
    }

    public ProductList(int idProduct, int idOrder) {
        this.productListPK = new ProductListPK(idProduct, idOrder);
    }

    public ProductListPK getProductListPK() {
        return productListPK;
    }

    public void setProductListPK(ProductListPK productListPK) {
        this.productListPK = productListPK;
    }

    public BigInteger getCount() {
        return count;
    }

    public void setCount(BigInteger count) {
        this.count = count;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Orders getOrders() {
        return orders;
    }

    public void setOrders(Orders orders) {
        this.orders = orders;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productListPK != null ? productListPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductList)) {
            return false;
        }
        ProductList other = (ProductList) object;
        if ((this.productListPK == null && other.productListPK != null) || (this.productListPK != null && !this.productListPK.equals(other.productListPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.ProductList[ productListPK=" + productListPK + " ]";
    }
    
}
